<#include "common_var.include"/> 
<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@include file="/common/header.jsp" %>
<link rel="stylesheet" type="text/css" href="<@jspEl "func == 'ctx'"/>/scripts/ztree/zTreeStyle/zTreeStyle.css" />
<script type="text/javascript" src="<@jspEl "func == 'ctx'"/>/scripts/ztree/jquery.ztree.js"></script>
<script type="text/javascript">
	$(document).ready(function() {refreshTree();});
	var treeObj;
	var setting = {
		data:{simpleData:{enable:true,idKey: "id",pIdKey: "pId"}},
		async: {
			enable: true,
			url: "${classNameLower}Action!getTree.action"
		},
		callback : {
	      	onClick: zTreeOnClick,
	      	onAsyncSuccess: zTreeOnAsyncSuccess
	    }
	};
	function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
		var currentRefreshId = '<@jspEl "func == 'recordId'"/>';
		if(currentRefreshId!=''){
			currentRefreshId = parseInt(currentRefreshId);
		}else{
			var nodes = treeObj.getNodes();
			currentRefreshId=nodes[0].id;
		}
		var nodes = treeObj.getNodesByParam("id", currentRefreshId, null);
		treeObj.selectNode(nodes[0]);
		loadEditView(currentRefreshId);
	}
	
	function zTreeOnClick(event, treeId, treeNode) {
		loadEditView(treeNode.id);	
	}

	function loadEditView(treeId){
		$('#selNodeId').val(treeId);
		$('.colR .title').html("${entityCnName} 编辑");
		$('.colR .contant').empty();
		if(treeId){
			$('.colR .contant').load("${classNameLower}Action!input.action",{recordId:treeId});
		}
	}
				
	function refreshTree() {
		  treeObj = $.fn.zTree.init($("#treeObj"),setting,zNodes);
	}
	
	function doAction(act,rid){
		if('addR'==act){
			$('.colR .title').html("新增  根节点信息");
			$('.colR .contant').empty();
			$('.colR .contant').load("${classNameLower}Action!input.action");
		}else if('addS'==act){
			var selectedNode = treeObj.getSelectedNodes()[0];
			if(!selectedNode) {
				alert("新增子节点需要先请选择一个节点。");
				return;
			}
			$('.colR .title').html("新增  子节点信息");
			$('.colR .contant').empty();
			$('.colR .contant').load("${classNameLower}Action!input.action?",{recordId:$('#selNodeId').val()});
		}else if('del'==act){
			var selectedNode = typeTree.getSelectedNodes()[0];
			if(selectedNode){
				var rv = confirm("该操作将会删除数据，是否继续？\n\n确定->执行操作\n\n取消->返回 ");
				if(!rv)return;
				$('#editFormId').attr('action','${classNameLower}Action!delete.action?',{recordId:$('#selNodeId').val()});
				submitForm('editFormId');
			}else{
				alert('请选择删除的节点。');
				return;
			}
		}else if('save'==act){
			submitForm('editFormId');
		}
	}
</script>
</head>

<body>
	<div class="topnav"><p>模块 &gt;资源 &gt;资源&gt;${entityCnName} 编辑</p></div>
 	
 	<fktag:toolbar>
 		<fktag:toolItem cssClass="icon-add-big"  onclick="doAction('addR')" title="新增根节点"></fktag:toolItem>
 		<fktag:toolItem cssClass="icon-add-big"  onclick="doAction('addS')" title="新增子节点"></fktag:toolItem>
 		<fktag:toolItem cssClass="icon-delete-big" onclick="doAction('del')" title="删除"></fktag:toolItem>
 		<fktag:toolItem cssClass="icon-save-big" onclick="doAction('save')"  title="保存"></fktag:toolItem>
 	</fktag:toolbar>
<!--  -->
	<!--左列内容-->
	<div class="colL" >
		<!--标题栏 样式-->
		<div class="title"> ${entityCnName}树 </div>
		<div class="contant">
		<div>
			<ul id="treeObj" class="ztree"></ul>
		</div>
		<p><input id="selNodeId" type="hidden"/></p>
		</div>
	</div>
	<!--右列内容-->
	<div class="colR" >
 		<div class="title"></div>
	 	<div class="contant"></div>
	</div>
<jsp:include page="/common/show_action_message.jsp"></jsp:include>  
</body>
</html>